"""
    This file is used to generate delegate_gen.hpp

    @author: Wolfhead
"""

from codeParser import CodeParser

if __name__ == "__main__" :
    codeParser = CodeParser()
    code = codeParser.read("../acapella/delegate/delegate_gen_base.hpp");

    count = 10

    gen_target = open("../acapella/delegate/delegate_gen.hpp", "w+", 0)

    replace = {
        "DELEGATE_TEMPLATE_ARGS" : "",
        "DELEGATE_FUNCTION_ARGS" : "",
        "DELEGATE_FUNCTION_PARA" : "",
        "DELEGATE_CLASS_MEMBER" : "",
        "DELEGATE_CLASS_ASSIGN" : "",
        "DELEGATE_CLASS_PARA" : "",
        }


    i = 0;
    while (i <= count) :
        if i == 0:
            pass
        elif i == 1:
            replace["DELEGATE_TEMPLATE_ARGS"] = ", typename T0"
            replace["DELEGATE_FUNCTION_ARGS"] = "T0 t0"
            replace["DELEGATE_FUNCTION_PARA"] = ",T0 t0"
            replace["DELEGATE_CLASS_MEMBER"] = "T0 t0_;"
            replace["DELEGATE_CLASS_ASSIGN"] = ", t0_(t0)"
            replace["DELEGATE_CLASS_PARA"] = "t0_"
        else:
            replace["DELEGATE_TEMPLATE_ARGS"] += ", typename T%d" % (i - 1,)
            replace["DELEGATE_FUNCTION_ARGS"] += ", T%d t%d" % (i - 1, i - 1)
            replace["DELEGATE_FUNCTION_PARA"] += ", T%d t%d" % (i - 1, i - 1)
            replace["DELEGATE_CLASS_MEMBER"] += "T%d t%d_;" % (i - 1, i - 1)
            replace["DELEGATE_CLASS_ASSIGN"] += ", t%d_(t%d)" %(i - 1, i - 1)
            replace["DELEGATE_CLASS_PARA"] += ", t%d_" % (i - 1)

        gen_target.write(codeParser.parse(code, replace));

        i += 1

    gen_target.close()
    print("finished")
            
    
